<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="lcy">
    <script src="../jquery-3.1.1.js"></script>
    <title></title>
    <style>
        main{
            height: 2000px;
            width: 100%;
            background-color: skyblue;
        }
        div{
            position: relative;
        }
        span{
            display: inline-block;
        }
        .shang span:nth-child(1){
            background-image: url(../images/scroll.png); 
            width: 15px;
            height: 40px;
            position: absolute;
            right: 0;
            top: 600px;
        }
        .shang span:nth-child(2){
            height: 40px;
            width: 100px;
            background-color: darkred;
            position: absolute;
            right: 0;
            top: 600px;
            color: white;
            text-align: center;
            line-height: 40px;
            border-top-left-radius: 20px;
            border-bottom-left-radius: 20px;
            display: none;
            
        }
        .xia span:nth-child(1){
            background-image: url(../images/scroll.png); 
            width: 15px;
            height: 40px;
            background-position: 0 -80px;
            position: absolute;
            right: 0;
            top: 640px;
        }
        .xia span:nth-child(2){
            height: 40px;
            width: 100px;
            background-color: black;
            position: absolute;
            right: 0;
            top: 640px;
            color: white;
            text-align: center;
            line-height: 40px;
            border-top-left-radius: 20px;
            border-bottom-left-radius: 20px;
            display: none;
        }
    </style>
</head>
<body>
    <main>
        <div class="shang">
            <span></span>
            <span>回到顶部</span>
        </div>
        <div class="xia">
            <span></span>
            <span>回到底部</span>
        </div>
    </main>
</body>
</html>
<script>
    $('.shang').hover(function(){
        $(this).find('span:last-child').show();
    },function(){
        $(this).find('span:last-child').hide();
    },1000);
    $('.shang').click(function(){
        $(window).scrollTop(0);
    })
    $('.xia').hover(function(){
        $(this).find('span:last-child').show();
    },function(){
        $(this).find('span:last-child').hide();
    },1000)
    $('.xia').click(function(){
        $(window).scrollTop(2000);
    })
</script>